package com.lei.springbootpractice.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lei.springbootpractice.dao.EmpDao;
import com.lei.springbootpractice.dao.UserDao;
import com.lei.springbootpractice.pojo.EmpPojo;
import com.lei.springbootpractice.pojo.UserPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService  {
    @Autowired
    UserDao userDao;

    public void addUser(String userID,
                       String userName,
                       String password,
                       String email,String role){
        userDao.insert(new UserPojo(userID,userName,password,email,role));
    }

    public UserPojo getUserByUserID(String userID) {
        return userDao.selectById(userID);
    }

    public boolean validateLogin(String userID, String password) {
        UserPojo user = getUserByUserID(userID);
        return user != null && user.getPassword().equals(password);
    }
    public List<UserPojo> getAllUsers() {
        return userDao.selectList(null); // 获取全部用户
    }

    public List<UserPojo> getUsersByRole(String role) {
        QueryWrapper<UserPojo> wrapper = new QueryWrapper<>();
        wrapper.eq("role", role);
        return userDao.selectList(wrapper);
    }

    public List<UserPojo> getCouriers() {
        QueryWrapper<UserPojo> query = new QueryWrapper<>();
        query.eq("role", "courier");
        return userDao.selectList(query);
    }


    public boolean deleteUser(String userId) {
        return userDao.deleteById(userId) > 0;
    }
}